package com.ruoyi.project.wenyanwen.sqlitestyle.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.wenyanwen.sqlitestyle.domain.SqliteStyle;
import com.ruoyi.project.wenyanwen.sqlitestyle.service.ISqliteStyleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Sqlite样式Controller
 *
 * @author shixiangwen
 * @date 2021-03-15
 */
@Controller
@RequestMapping("/wenyanwen/sqlitestyle")
public class SqliteStyleController extends BaseController {
    private String prefix = "wenyanwen/sqlitestyle";

    @Autowired
    private ISqliteStyleService sqliteiStyleService;

    @RequiresPermissions("wenyanwen:sqlitestyle:view")
    @GetMapping()
    public String sqlitestyle() {
        return prefix + "/sqlitestyle";
    }

    /**
     * 查询Sqlite样式列表
     */
    @RequiresPermissions("wenyanwen:sqlitestyle:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SqliteStyle sqliteiStyle) {
        startPage();
        List<SqliteStyle> list = sqliteiStyleService.selectSqliteStyleList(sqliteiStyle);
        return getDataTable(list);
    }

    /**
     * 导出Sqlite样式列表
     */
    @RequiresPermissions("wenyanwen:sqlitestyle:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SqliteStyle sqliteiStyle) {
        List<SqliteStyle> list = sqliteiStyleService.selectSqliteStyleList(sqliteiStyle);
        ExcelUtil<SqliteStyle> util = new ExcelUtil<SqliteStyle>(SqliteStyle.class);
        return util.exportExcel(list, "sqlitestyle");
    }

    /**
     * 新增Sqlite样式
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存Sqlite样式
     */
    @RequiresPermissions("wenyanwen:sqlitestyle:add")
    @Log(title = "Sqlite样式", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SqliteStyle sqliteiStyle) {
        return toAjax(sqliteiStyleService.insertSqliteStyle(sqliteiStyle));
    }

    /**
     * 修改Sqlite样式
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        SqliteStyle sqliteiStyle = sqliteiStyleService.selectSqliteStyleById(id);
        mmap.put("sqliteiStyle", sqliteiStyle);
        return prefix + "/edit";
    }

    /**
     * 修改保存Sqlite样式
     */
    @RequiresPermissions("wenyanwen:sqlitestyle:edit")
    @Log(title = "Sqlite样式", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SqliteStyle sqliteiStyle) {
        return toAjax(sqliteiStyleService.updateSqliteStyle(sqliteiStyle));
    }

    /**
     * 删除Sqlite样式
     */
    @RequiresPermissions("wenyanwen:sqlitestyle:remove")
    @Log(title = "Sqlite样式", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(sqliteiStyleService.deleteSqliteStyleByIds(ids));
    }
}
